import time

from selenium.webdriver.common.by import By
from base.page_base import BasePage
from config import BASE_URL


class Register(BasePage):
    phone = (By.ID, 'phone')
    password = (By.ID, 'password')
    verifycode = (By.ID, 'verifycode')
    get_phone_code = (By.ID, 'get_phone_code')
    phone_code = (By.ID, 'phone_code')
    lg_btn = (By.CLASS_NAME, 'lg-btn')
    # 成功文本元素
    success_text = (By.XPATH, "//*[text()='注册成功！']")
    # 失败文本元素
    fail_text = (By.CLASS_NAME, "reg-title")

    def open_url(self):
        self.driver.get(BASE_URL + '/common/member/reg')

    def input_phone(self, phone):
        self.base_input(self.phone, phone)

    def input_password(self, password):
        self.base_input(self.password, password)

    def input_verifycode(self, verifycode='8888'):
        self.base_input(self.verifycode, verifycode)

    def input_get_phone_code(self):
        self.base_click(self.get_phone_code)

    def input_phone_code(self, phone_code='666666'):
        self.base_input(self.phone_code, phone_code)

    def click_lg_btn(self):
        self.base_click(self.lg_btn)

    def get_success_text(self):
        return self.fd_element(self.success_text).text

    def get_fail_text(self):  # 失败文本
        return self.fd_element(self.fail_text).text

    def reqlster(self, phone, password, verifycode='8888', phone_code='666666'):
        self.input_phone(phone)
        self.input_password(password)
        self.input_verifycode(verifycode)
        self.input_get_phone_code()
        time.sleep(2)
        self.input_phone_code(phone_code)
        self.click_lg_btn()
